package com.lry.rpc.netty;

import com.alibaba.ttl.TransmittableThreadLocal;

import java.util.HashMap;
import java.util.Map;

public class RpcContext {

    public static TransmittableThreadLocal<Map<String, Object>> threadLocal = new TransmittableThreadLocal<>();

    public static Map<String,Object> getContext(){
        return threadLocal.get();
    }

    public static  void setMap(Map<String,Object> m){
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap();
            threadLocal.set(map);
        }
        map.putAll(m);
    }
    public static void set(String key, Object value) {
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap();
            threadLocal.set(map);
        }
        map.put(key, value);
    }


}
